package com.ruiysoft.service.order.util;

import com.ruiysoft.controller.order.vo.OrderDeliverVo;
import com.ruiysoft.controller.order.vo.OrderPlaceCusVo;
import com.ruiysoft.entity.common.UserInfo;
import com.ruiysoft.pub.core.Result;
import com.ruiysoft.pub.core.ResultCode;
import com.ruiysoft.pub.core.ResultGenerator;
import com.ruiysoft.service.logistics.ILogisticsQueryService;
import com.ruiysoft.service.order.bean.OrderIntfResultDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.Valid;

/**
 * Date : 2018/11/10
 *
 * @author WenJialu
 */
@Component
public class OrderCheckUtil {

	@Autowired
	ILogisticsQueryService iLogisticsQueryService;



	/**
	 * 用户下单校验
	 * @param userInfo
	 * @param orderPlaceVo
	 * @return
	 */
	public Result<OrderIntfResultDto> checkOrderPlaceCustomer(UserInfo userInfo, @Valid OrderPlaceCusVo orderPlaceVo) {
		return ResultGenerator.genSuccessResult();
	}

	public Result checkOrderPrePlaceCustomer(@Valid OrderPlaceCusVo orderPlaceVo) {
		Result result = ResultGenerator.genSuccessResult();
		if(orderPlaceVo == null
				|| orderPlaceVo.getOrderPlaceSkus() == null
				|| orderPlaceVo.getOrderPlaceSkus().size() == 0){
			result.setBizCode(ResultCode.CODE_COMMON_ERROR);
			result.setBizMessage("商品列表为空");
		}
		return result;
	}

	public Result checkOrderDeliver(OrderDeliverVo orderDeliverVo) {
		if (null == orderDeliverVo) {
			return ResultGenerator.genFailResult("请求数据不能为空");
		}
		StringBuilder msg = new StringBuilder();
		if (StringUtils.isBlank(orderDeliverVo.getOrderNo())) {
			msg.append(",订单号");
		}
		if (StringUtils.isBlank(orderDeliverVo.getLogisticsNo())) {
			msg.append(",物流单号");
		}
		if(StringUtils.isEmpty(orderDeliverVo.getCode())){
			msg.append(",快递公司");
		}
		if( msg.length()>0){
			return ResultGenerator.genFailResult(msg.append("不能为空").toString().replaceFirst(",", ""));
		}
		//TODO 是否增加这个校验呢？
        //iLogisticsQueryService.validate(orderDeliverVo.);
		return ResultGenerator.genSuccessResult();
	}
}
